﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestWin
{
    public partial class DevListForm : Form
    {
        public DevListForm()
        {
            InitializeComponent();

            dataGridView1.DataSource = AppInfo.ListDevs;
           
        }

       string ParseMediaIPFromUrl(String sspurl)
        {
             var sss=     sspurl.Split(';').ToList<String>();
	        foreach (String cc in sss)
	        {
                int index = cc.LastIndexOf("ssp://");
                if (index != -1)
                {
                    int iEnd = cc.LastIndexOf(":");
                    return cc.Substring(6, iEnd - 6);
                }
            }
            return "";
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = e.RowIndex;
            AppInfo.DevInfo devInfo = AppInfo.ListDevs[index];
            DataGridViewColumn colu = dataGridView1.Columns[e.ColumnIndex];
            if(colu.Name=="Sd" || colu.Name == "Look")
            {
                //在线状态
                if (devInfo.status == 2)
                {
                    string Ip = ParseMediaIPFromUrl(devInfo.dataserver);
                    if (colu.Name == "Look")
                    {
                        Form1 ff = new Form1();
                        ff.SetIpInfo(devInfo.hid, Ip);
                        ff.ShowDialog();
                    }else if (colu.Name == "Sd"){
                        SdForm sd = new SdForm();
                        sd.SetIpInfo(devInfo.hid, Ip);
                        sd.GetSdRoot();
                        sd.ShowDialog();
                    }
                }
            }
            
        }
    }
}
